package com.h3c.nem.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author chenyifan
 * @date 2022/6/2 16:43
 * 预备员工填写信息流程枚举
 */
@Getter
@AllArgsConstructor
public enum OfferWorkerFillStageEnum {

    /**
     * 未填写
     */
    NO_FILL(0, "未填写"),
    /**
     * 1已登录待确认文件
     */
    UN_CONFIRM(1, "已登录待确认文件"),
    /**
     * 基本信息
     */
    FILL_ING(2, "填写中"),
    /**
     * 填写完成
     */
    FILL_FINISH(3, "填写完成");

    @EnumValue
    private final Integer code;

    @JsonValue
    private final String statusName;

    /**
     * code 作为 key，封装为 Map
     */
    private static final Map<Integer, OfferWorkerFillStageEnum> CODE_MAP = Stream
            .of(OfferWorkerFillStageEnum.values())
            .collect(Collectors.toMap(OfferWorkerFillStageEnum::getCode, Function.identity()));


    /**
     * 静态工厂反序列化
     *
     * @param key code
     * @return 评论的类型枚举
     */
    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static OfferWorkerFillStageEnum valueOfKey(Integer key) {
        return Optional.ofNullable(CODE_MAP.get(key))
                .orElseThrow(() -> new IllegalArgumentException(String.valueOf(key)));
    }
}
